import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const scrollBehavior = (to, from, savedPosition) => {
    if (to.meta && to.meta.savePosition && savedPosition) {
        return savedPosition
    }

    const position = {}
    if (to.hash) {
        position.selector = to.hash
    } else {
        position.x = 0
        position.y = 0
    }

    return position
}


const routes = [{
        path: '/',
        redirect: '/infodetail'
    },
    {
        path: '/infodetail',
        name: '信息详情页',
        component: resolve => {
            require.ensure([], () => {
                resolve(require('views/Info/Detail.vue'))
            })
        }
    },
]

const router = new VueRouter({
    scrollBehavior,
    routes
})

export default router